
import matplotlib.pyplot as plt
from kNearBase import *

def createDataSet():
    group = array([[1.0,1.1], [1.0,1.0], [0,0], [0,0.1]])
    labels = ['A', 'A', 'B', 'B']
    return group, labels


def datingClassTest():
    hoRatio = 0.10
    datingDataMat, datingLabels = file2matrix("datingTestSet2.txt")
    normMat, ranges, minVals = autoNorm(datingDataMat)
    m = normMat.shape[0]
    numTestVecs = int(m*hoRatio)
    errorCount = 0.0
    print("the total count is :%d" % numTestVecs)
    for i in range(numTestVecs):
        classifierResult = classify0(normMat[i, :], normMat[numTestVecs:m, :], datingLabels[numTestVecs:m], 3)

        if(classifierResult != datingLabels[i]):
            errorCount += 1.0
            print("the classifier came back with: %d, the real answer is: %d" % (classifierResult, datingLabels[i]))
    print("TestNum: %d, errorNum: %d" %(numTestVecs, errorCount))
    print("the total error rate is : %.2f%%" %(errorCount*100/ float(numTestVecs)))

def classifyPerson():
    resultList = ['not at all', 'in small does', 'in large doses']
    percentTats = float(input(
        "percentage of time spend playing video games?"))
    ffMiles = float(input("frequent flier miles earned per year?"))
    iceCream = float(input("iters of ice cream consumed per years?"))
    datingDataMat, datingLabels = file2matrix("datingTestSet2.txt")
    normMat, ranges, minVals = autoNorm(datingDataMat)
    inArr = array([ffMiles, percentTats, iceCream])
    classifierResult = \
        classify0((inArr - minVals)/ranges, normMat, datingLabels, 3)
    print("You will probably like this person: ", resultList[classifierResult - 1])

def pltShow():
    datingDataMat, datingLabels = file2matrix("datingTestSet2.txt")
    fig = plt.figure()
    ax = fig.add_subplot(111)
    # ax.scatter(datingDataMat[:, 1], datingDataMat[:, 2])
    # ax.scatter(datingDataMat[:, 0], datingDataMat[:, 1], 15.0*array(datingLabels), 15.0*array(datingLabels))
    normDataSet, ranges, minVals = autoNorm(datingDataMat)
    ax.scatter(normDataSet[:, 0], normDataSet[:, 1], 15.0 * array(datingLabels), 15.0 * array(datingLabels))
    plt.show()


pltShow()
datingClassTest()
classifyPerson()
